package com.ty.controller;

import cn.hutool.json.JSONUtil;
import com.ty.dto.Order;
import com.ty.dto.OrderQuery;
import com.ty.dto.OrderingDto;
import com.ty.dto.OrderingOk;
import com.ty.feignclients.OrderServiceClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/user")
@Slf4j
public class UserController {

    @Autowired
    OrderServiceClient orderServiceClient;

    @GetMapping("/ordering")
    public String ordering()
    {
       OrderingOk ordering = orderServiceClient.ordering(new OrderingDto().setUserName("ling").setProductName("歌行四方专辑"));
        return JSONUtil.toJsonStr(ordering);
    }

    @GetMapping("/order")
    public  List<Order> order()
    {
        List<Order> orders = orderServiceClient.select(new OrderQuery().setUserId(1).setId(12l));
        return orders;
    }

    @GetMapping("/sleep")
    public  String sleep(Integer time)
    {
        log.debug("开始请求了");
        return orderServiceClient.sleep(time);

    }
}
